package my.jwds.p111;

import my.jwds.p94.TreeNode;

public class MinDepth {
    public static void main(String[] args) {
        MinDepth o = new MinDepth();
        TreeNode node = TreeNode.to_binary(new int[]{1,2,3,4,5,6});
        System.out.println(o.minDepth(node));
    }
    public int minDepth(TreeNode root) {
        if (root == null)return 0;
        return minDepth(root,0);
    }
    public int minDepth(TreeNode root,int now) {
        if (root == null)return Integer.MAX_VALUE;
        now++;
        if (root.left == null && root.right == null)return now;
        int left = minDepth(root.left,now);
        int right = minDepth(root.right,now);
        return left > right ? right:left;
    }
}
